package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.pojo.GoodsSeries;
import com.gxa.zhonglong.service.GoodsSeriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author wanjun
 * @version 1.0
 * @date 2021/11/1 15:47
 */
@CrossOrigin
@RestController
@Api(tags = "商品系列接口")
@RequestMapping("/goodSeries")
public class GoodSeriesController {
    @Autowired
    GoodsSeriesService goodsSeriesService=null;
    @ApiOperation("添加(不传id)/修改的接口(传id)")
    @PostMapping("/insertOrUpdate")
    public Map insertOrUpdate(GoodsSeries goodsSeries) {
        if(goodsSeries.getId()==null){
            goodsSeriesService.insert(goodsSeries);
        }else {
            goodsSeriesService.insert(goodsSeries);
        }
        JsonResult jsonResult = new JsonResult("1", "成功", "");
        return jsonResult.getDataMap();
    }
    @ApiOperation("删除的方法,传一个id的数组")
    @PostMapping("/delete")
    public Map delete(List<Long> listId) {
       goodsSeriesService.delete(listId);
        JsonResult jsonResult = new JsonResult("1", "成功", "");
        return jsonResult.getDataMap();
    }

    @ApiOperation("全查询")
    @PostMapping("/selectAll")
    public Map selectAll() {
        List<GoodsSeries> goodsSeries = goodsSeriesService.selectAll();
        JsonResult jsonResult = new JsonResult("1", "成功", goodsSeries);
        return jsonResult.getDataMap();

    }
}
